#! /usr/bin/python
import ctypes
import numpy as np

LIBRARY_PATH = './c_functions.so'
_c_functions = ctypes.CDLL(LIBRARY_PATH)

# test add.c 
_c_functions.add.argtypes = [ctypes.c_int, ctypes.c_int]
_c_functions.add.restype = ctypes.c_int
print ">>> _c_functions.add(ctypes.c_int(2), ctypes.c_int(2))"
print ">>>",
print _c_functions.add(ctypes.c_int(2), ctypes.c_int(2))

# test avg_array.c 
_c_functions.avg_array.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int]
_c_functions.avg_array.restype = ctypes.c_double
print ">>> data = np.array(range(10))"
print ">>>",
data = np.arange(10.)
print data
print "# always use doubles when dealing with numpy float arrays"
print ">>> _c_functions.avg_array(data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ctypes.c_int(10))"
print ">>>",
print _c_functions.avg_array(data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ctypes.c_int(10))

# test switch_initials.c
_c_functions.switch_initials.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
_c_functions.switch_initials.restype = None
print '>>> string1 = ctypes.c_char_p("Tizio"), string2 = ctypes.c_char_p("Caio")'
print '>>> _c_functions.switch_initials(string1, string2)'
string1 = ctypes.c_char_p("Tizio")
string2 = ctypes.c_char_p("Caio")
_c_functions.switch_initials(string1, string2)
print string1.value
print string2.value

# test vector.cpp
_c_functions.vector_play.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.c_int]
array = (ctypes.c_int * 10)()
array[1] = 12
array[2] = 14
print ">>> _c_functions.vector_play(array, ctypes.c_int(10))"
_c_functions.vector_play(array, ctypes.c_int(10))


